package com.jaws.demo.service;

import com.jaws.core.common.util.DateUtil;
import com.jaws.demo.dao.AccountInfoDao;
import com.jaws.demo.vo.AccountInfo;
import com.jaws.demo.vo.BatchOpenAccountReq;
import com.jaws.demo.vo.OpenAccountReq;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AccountServiceImpl {

	@Resource
	AccountInfoDao accountInfoDao;

	@Transactional
	public void openAccount(BatchOpenAccountReq params) {
		List<OpenAccountReq> list = params.getList();

		accountInfoDao.insert(buildAccountInfo(list.get(0)));
		System.out.println(1 / 0);
		accountInfoDao.insert(buildAccountInfo(list.get(1)));
	}


	/**
	 * 创建用户开户信息
	 *
	 * @param req
	 * @return
	 * @author maojian
	 * @date 2017-05-27 08:48:12
	 * @since v1.0.0
	 */
	private AccountInfo buildAccountInfo(OpenAccountReq req) {
		AccountInfo accountInfoPo = new AccountInfo();
		accountInfoPo.setUserId(req.getUserId());
		accountInfoPo.setAccountNo("lampard18612997785");
		accountInfoPo.setAccountName(req.getUserName());
		accountInfoPo.setDepositAccountNo(req.getDepositAccountNo());
		accountInfoPo.setCreateTime(DateUtil.getCurrentDateTime());
		accountInfoPo.setUpdateTime(accountInfoPo.getCreateTime());
		accountInfoPo.setRemark(req.getRemark() == null ? "" : req.getRemark());
		accountInfoPo.setAccountType(req.getAccountType().getCode());
		accountInfoPo.setLoginPwd(req.getLoginPwd());
		accountInfoPo.setDrawPwd(req.getDrawPwd());
		return accountInfoPo;
	}

}
